package application;

import android.app.Application;
import android.content.Context;

import com.lanou.horo.myapplication.dbdao.DaoMaster;
import com.lanou.horo.myapplication.dbdao.DaoSession;
import com.lanou.horo.myapplication.dbdao.HistoryEntity;
import com.lanou.horo.myapplication.dbdao.HistoryEntityDao;
import com.lanou.horo.myapplication.dbdao.PersonEntity;

import cn.jpush.android.api.JPushInterface;
import dbdao.HistoryDBhelper;
import utils.adapter.HistoryDbAdpter;

/**
 * Created by Risky on 15/10/28.
 */
public class BasisApplication extends Application {
    private static Context mContext;
    public static boolean mIsSleepClockSetting = false;
    private static boolean isLogin = false;
    private static DaoMaster daoMaster;//daomaster是为了获得daoSession对象
    private static DaoSession daoSession;//会话
    private static long userId = 0;
    private HistoryDBhelper historyDBhelper;
    private static PersonEntity user;

    public static PersonEntity getUser() {
        return user;
    }

    public static void setUser(PersonEntity user) {
        BasisApplication.user = user;
    }

    public static long getUserId() {
        return userId;
    }

    public static void setUserId(long userId) {
        BasisApplication.userId = userId;
    }

    public static boolean isLogin() {
        return isLogin;
    }

    public static void setIsLogin(boolean isLogin) {
        BasisApplication.isLogin = isLogin;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mContext = getApplicationContext();
        JPushInterface.setDebugMode(true);
        JPushInterface.init(this);


    }


    //使用静态方法
    public static DaoMaster getDaoMaster() {

        if (daoMaster == null) {

            //创建一个新的OpenHelper
            DaoMaster.OpenHelper helper = new DaoMaster.DevOpenHelper(mContext, //静态方法里面使用静态变量
                    "lanou3g", //数据库名称
                    null);
            daoMaster = new DaoMaster(helper.getWritableDatabase());//初始化
        }
        return daoMaster;
    }

    //单例
    public static DaoSession getDaoSession() {
        if (daoSession == null) {
            if (daoMaster == null) {
                getDaoMaster();
                daoSession = daoMaster.newSession();
            }

        }


        return daoSession;

    }

    public static Context getContext() {
        return mContext;
    }
}
